<?php
$popular_food_name        = "34534545 Tuna";
$popular_food_description = "A double layer of sear-sizzled 100% pure beef mingled with special sauce on a sesame seed bun and topped with melty American cheese, crisp lettuce, minced onions and tangy pickles.";

require('mysqli_connect.php'); // Connect to the db.

function debug_to_console($data)
{
    if (is_array($data))
        $output = "<script>console.log( 'Debug Objects: " . implode(',', $data) . "' );</script>";
    else
        $output = "<script>console.log( 'Debug Objects: " . $data . "' );</script>";
    
    echo $output;
}

// for adding the Categories
function list_categories()
{
    
    // Make the connection:
    $dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die('Could not connect to MySQL: ' . mysqli_connect_error());
    
    // Set the encoding...
    mysqli_set_charset($dbc, 'utf8');
    // Set the encoding...
    mysqli_set_charset($dbc, 'utf8');
    $result = mysqli_query($dbc, "select distinct(Food_Category) from nutrition_master");
    
    if ($result) { // If it ran OK, display the records.
        
        while ($row = mysqli_fetch_array($result)) {
            $Food_Category = $row['Food_Category'];
            debug_to_console("$Food_Category");
            echo '<li class="odd"><a href="search.php?type=category&value=' . $Food_Category . '">';
            echo $Food_Category;
            echo '</a></li>';
        }
        
        
        mysqli_free_result($result); // Free up the resources.
        
    } else { // If it did not run OK.
        
        // Debugging message:
        echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>';
        
    } // End of if ($r) IF.
    
    mysqli_close($dbc); // Close the database connection.
} // End of the function list_categories.

// for adding the Brand Names
function list_brands()
{
    
    // Make the connection:
    $dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die('Could not connect to MySQL: ' . mysqli_connect_error());
    
    // Set the encoding...
    mysqli_set_charset($dbc, 'utf8');
    
    $result = mysqli_query($dbc, "select distinct(brand_name) from nutrition_master");
    if ($result) { // If it ran OK, display the records.
        
        while ($row = mysqli_fetch_array($result)) {
            $brand_name = $row['brand_name'];
            debug_to_console("$brand_name");
            echo '<li class="odd"><a href="search.php?type=brand&value=' . $brand_name . '">';
            echo $brand_name;
            echo '</a></li>';
        }
        
        
        mysqli_free_result($result); // Free up the resources.
        
    } else { // If it did not run OK.
        
        // Debugging message:
        echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>';
        
    } // End of if ($r) IF.
    
    mysqli_close($dbc); // Close the database connection.
} // End of the function list_categories.




// for adding the Brand Names
function list_popular_foods()
{
    // Make the connection:
    $dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die('Could not connect to MySQL: ' . mysqli_connect_error());
    
    // Set the encoding...
    mysqli_set_charset($dbc, 'utf8');
    
    $result = mysqli_query($dbc, "select food_Name, food_id, brand_Name,image_url from nutrition_master limit 1,9");
    if ($result) { // If it ran OK, display the records.
        
        while ($row = mysqli_fetch_array($result)) {
            $food_Name  = $row['food_Name'];
            $food_id    = $row['food_id'];
            $brand_Name = $row['brand_Name'];
            $image_url  = $row['image_url'];
            debug_to_console("$food_Name");
            echo '<div class="prod_box">
        	<div class="top_prod_box"></div>
            <div class="center_prod_box">
                 <div class="product_title"><a href="details.php?food_id=' . $food_id . '">';
            echo $food_Name;
            echo '</a></div>
                 <div class="product_img"><a href="details.php?food_id=' . $food_id . '"><img src="';
            echo $image_url;
            echo '"   width="94" height="92" alt="" title="" border="0" /></a></div>
                 <div class="prod_price"><span class="price">';
            echo $brand_Name;
            echo '</span></div>
            </div>
            <div class="bottom_prod_box"></div>
            <div class="prod_details_tab">
			
           <a href="details.php?food_id=' . $food_id;
            echo '" class="prod_details">details</a>
           </div>
        </div>';
        }
        
    }
    mysqli_close($dbc); // Close the database connection.
    
} // End of the function list_categories.

function list_top_food_items($number)
{
    if ($number = 1) {
    } else if ($number = 2) {
        
        $popular_food_name        = "Spicy Tuna";
        $popular_food_description = "You'll love this tasty new sub! Try it our way with our delicious tuna, creamy Sriracha sauce, tomatoes, green peppers, and jalapenos, or add your favorite veggies to make it yours!";
    }
}


function redirect($url, $statusCode = 303)
{
    header('Location: ' . $url, true, $statusCode);
    die();
}

?>




<?php
include('header.php');
?>
    
    	<div class="left_content">
			<div class="title_box">Categories</div>
			<ul class="left_menu">
                <?php
list_categories();
?>
            </ul>
            
             <div class="title_box">Newsletter</div>  
		     <div class="border_box">
				<input type="text" name="newsletter" class="newsletter_input" value="your email"/>
		        <a href="#" class="join">join</a>
		     </div> 
            
            
            <div class="banner_adds">
     			<a id="left_banner" href="#"><img src="../images/mcd_banner.jpg" alt="" title="" border="0" /></a>
     		</div>   
		</div>

		</div>

		<div class="center_content">
			<div class="center_title_bar">Popular Food Items</div>
<?php
list_popular_foods();
?>
        </div>
		<!-- end of center content -->

		<div class="right_content">
			<div class="title_box">Brand Name</div>
			<ul class="left_menu">
<?php
list_brands();
?>
            </ul>
            
            <div class="banner_adds">
     			<a id="right_banner" href="#"><img src="../images/subway_banner.jpg" alt="" title="" border="0" /></a>
     		</div>  
		</div>
		<!-- end of right content -->

<?php
include('footer.php');
?>